Reduce temp var creation during flatten step, re-enable rewrite test#1120
Reduce temp var creation during flatten step, re-enable rewrite test#1120
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (isEffectivelyPure(r.expr) | ||
| || isUnchangedVarAccess(r.expr, results, i + 1) | ||
| || i >= withStmts) { |
There was a problem hiding this comment.
Var reads can be reordered past impure statements
The new isUnchangedVarAccess guard in flattenExprs now reuses an ImVarAccess when no direct ImSet to the same var is found, causing the first argument to be evaluated after later statements. However, ImVarAccess is classified as ReadsGlobals rather than Pure (PurityLevels.java:32‑34), so its value can change across any side effect. The write check only looks for ImSet targets (writesVar at lines 515‑524) and ignores other impure statements such as function-call statements (ImStmt includes ImExpr, parserspec/jass_im.parseq lines 74‑83), so a later statement expression that calls a mutating function will bypass the temp creation and the read will occur after the mutation (e.g., foo(g, (mutate(); ...)) now reads the updated g). This reorders observable effects compared to the original left-to-right evaluation.
Useful? React with 👍 / 👎.
No description provided.